import {
  Entity,
  Column,
  CreateDateColumn,
  UpdateDateColumn,
  PrimaryColumn,
  OneToOne,
  JoinColumn
} from "typeorm";
import { BblAttach } from "./attach.entity";
import { BblPrizeGroup } from "./prize.group.entity";

/**
 * 抽奖活动奖品配置表
 */
@Entity("BBL_PRIZE")
export class BblPrize {
  @PrimaryColumn({
    name: "ID",
    type: "varchar",
    length: 50,
    comment: "奖品主键ID（业务自定义）"
  })
  id: string;

  @Column({
    name: "PRIZE_NAME",
    type: "varchar",
    length: 100,
    nullable: false,
    comment: "奖品名称"
  })
  prizeName: string;

  @Column({
    name: "PRIZE_DESC",
    type: "text",
    nullable: true,
    comment: "奖品描述"
  })
  prizeDesc: string;

  @OneToOne(() => BblAttach, { createForeignKeyConstraints: false })
  @JoinColumn({ name: "PRIZE_IMAGE_ATTACHMENT_ID" })
  prizeImage: BblAttach;

  @OneToOne(() => BblPrizeGroup, { createForeignKeyConstraints: false })
  @JoinColumn({ name: "GROUP_ID" })
  prizeGroup: BblPrizeGroup;

  @Column({
    name: "PRIZE_TYPE",
    type: "int",
    nullable: false,
    comment: "奖品类型（1-实物奖品，2-虚拟奖品，3-优惠券等）"
  })
  prizeType: number;

  @Column({
    name: "PRIZE_QUANTITY",
    type: "int",
    nullable: false,
    comment: "奖品数量"
  })
  prizeQuantity: number;

  @Column({
    name: "REMAINING_QUANTITY",
    type: "int",
    nullable: false,
    comment: "剩余数量"
  })
  remainingQuantity: number;

  @Column({
    name: "SORT_ORDER",
    type: "int",
    default: 0,
    comment: "显示排序"
  })
  sortOrder: number;

  /**
   * 权重，决定奖品在抽奖中的权重，默认值为0
   */
  @Column({
    name: "WEIGHT",
    type: "int",
    default: 0,
    comment: "权重"
  })
  weight: number;

  @CreateDateColumn({
    name: "CREATED_AT",
    type: "timestamp",
    precision: 6,
    nullable: true,
    default: () => "CURRENT_TIMESTAMP(6)",
    comment: "创建时间"
  })
  createdAt: Date;

  @UpdateDateColumn({
    name: "UPDATED_AT",
    type: "timestamp",
    precision: 6,
    nullable: true,
    default: () => "CURRENT_TIMESTAMP(6)",
    onUpdate: "CURRENT_TIMESTAMP(6)",
    comment: "更新时间"
  })
  updatedAt: Date;

  @Column({
    name: "CREATED_BY",
    type: "varchar",
    length: 50,
    nullable: true,
    comment: "创建人ID"
  })
  createdBy: string;

  @Column({
    name: "UPDATED_BY",
    type: "varchar",
    length: 50,
    nullable: true,
    comment: "更新人ID"
  })
  updatedBy: string;

  @Column({
    name: "IS_DELETED",
    type: "tinyint",
    default: 0,
    comment: "是否删除（0-否，1-是）"
  })
  isDeleted: number;
}
